/**
 * kl yy-ds @2021
 */
package com.cxps.cloud.code;

import java.util.Random;

/**
 * 手机验证码
 *
 * @author YouCai.Liu
 * @since 2021/11/19
 * ...
 */
public class PhoneCode {

    // 获取随机数对象
    private static Random r = new Random();

    private static String codes = "0123456789";

    /**
     * 获取随机字符
     *
     * @return
     */
    private static char randomChar() {
        int index = r.nextInt(codes.length());
        return codes.charAt(index);
    }

    /**
     * 生成6位验证码
     * @return
     */
    public static String buildCode(){
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 6; i++) {
            String s = randomChar() + "";
            sb.append(s);
        }
        return sb.toString();
    }
}
